# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=rtmpdump
pkgbase=mingw-w64-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
pkgver=r514.c5f04a5
pkgrel=2
pkgdesc="A tool to download rtmp streams (mingw-w64)"
arch=('any')
url="https://rtmpdump.mplayerhq.hu/"
license=('GPL2' 'LGPL2.1')
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "git")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-gmp"
         "${MINGW_PACKAGE_PREFIX}-gnutls"
         "${MINGW_PACKAGE_PREFIX}-nettle"
         "${MINGW_PACKAGE_PREFIX}-zlib")
options=('strip' 'staticlibs')
source=("$_realname::git+https://git.ffmpeg.org/rtmpdump"
        0001-mingw.mingw.patch
        0002-no-fPIC.mingw.patch
        0003-better-w32-threading.all.patch
        0004-gnu_printf.all.patch
        0005-fix-unused-var-warning.all.patch
        0006-deprecated-gnutls-type.all.patch
        0007-cast-appropriately-for-nettle.all.patch
        0008-unused-variable-warning-fix.all.patch
        0009-correct-cast.all.patch
        0011-fix-parallel-install.all.patch
        0012-no-sbin.patch
        0013-no-extra-dll.patch)
sha256sums=('SKIP'
            'cfd82cad49aa6e84f5316befce5d223d1861b6997bfbf7d655503b71878f5423'
            '7c6f0360249996fa6b994bef025b742cdf7748a255f19d8cc46c50bbe4ff99c9'
            '0a2f24ded2c025d324189a8246162f8f906afd0c1650ed31b6e748874ea31ea1'
            'eb6af4f8a570ff8274c0c412901e719cd0ef14badcc88358d7c36cb3ff29df17'
            '4afc6626fa29398a086a9385f251db9c2e5a885cf08b43c7aa88c16a91d72278'
            '717b514c7686a39262edbb84791145cb805261f02a76b71f558db4ca4d9d3c24'
            'c12973df7e9f01020f31acef6778884b02a6d6bdd6310d2d5396b4dcefdbf907'
            'c8377f1bdde89833148a496509a35439e2ac99fa41b0ceec73ccecb298fccb27'
            'c3ac95d2b39fed97587f0cf379abea50d43708ab5bd5e49f43d618ae383fa108'
            'b42327849d05aa9df44e3d47c98f5a49adeb2a5ff477b750f7ed780847cf0849'
            '4ba58ee78346e5e472671006adb91e581177c706b01d71f8e6cbd3aa4e776e2b'
            'a663ed0927d9e1b0487f4a61cf0d5833344dde80741e95b102f8e78495768c89')

pkgver() {
  cd "${srcdir}/${_realname}"
  printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cd "${srcdir}/${_realname}"
  patch -p1 -i ${srcdir}/0001-mingw.mingw.patch
  patch -p1 -i ${srcdir}/0002-no-fPIC.mingw.patch
  patch -p1 -i ${srcdir}/0003-better-w32-threading.all.patch
  patch -p1 -i ${srcdir}/0004-gnu_printf.all.patch
  patch -p1 -i ${srcdir}/0005-fix-unused-var-warning.all.patch
  patch -p1 -i ${srcdir}/0006-deprecated-gnutls-type.all.patch
  patch -p1 -i ${srcdir}/0007-cast-appropriately-for-nettle.all.patch
  patch -p1 -i ${srcdir}/0008-unused-variable-warning-fix.all.patch
  patch -p1 -i ${srcdir}/0009-correct-cast.all.patch
  patch -p1 -i ${srcdir}/0011-fix-parallel-install.all.patch
  patch -p1 -i ${srcdir}/0012-no-sbin.patch
  patch -p1 -i ${srcdir}/0013-no-extra-dll.patch
}

build() {
  cp -rf "${srcdir}/$_realname" "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  make CC=gcc LD=ld AR=ar SYS=mingw
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p ${pkgdir}${MINGW_PREFIX}/lib
  make CC=gcc LD=ld AR=ar SYS=mingw prefix=${MINGW_PREFIX} mandir=${MINGW_PREFIX}/share/man DESTDIR="${pkgdir}" install
}
